<!--
 * @Author:  airhang
 * @Date: 2020-06-12 10:55:23
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Socket\index.html
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Airhang</title>
</head>

<body>
    <script>
        var wbsClient = null;
        //判断当前浏览器是否支持WebSocket
        if ('WebSocket' in window) {
            wbsClient = new WebSocket("ws://localhost:3030");
            wbsClient.onopen = function (res) {
                console.log("连接socket", res);
                wbsClient.send("HIHI")
            }
            wbsClient.onmessage = function (res) {
                console.log("接收数据", res)
            }
            wbsClient.onclose = function (res) {
                console.log("服务已关闭")
            }
        } else {
            alert('当前浏览器不支持websocket')
        }
    </script>
</body>

</html>